#include "DocumentFile.h"
#include <iostream>

using std::ios;
using std::ifstream;
using std::cout;
using std::endl;

/********************************************************************************************/
DocumentFile::DocumentFile(string name, tDocumentNumber _id ):File(name)
{
	eof = false;
	Id = _id;
	_endBuffer = true;
	offset = 1;
}
/********************************************************************************************/
DocumentFile::~DocumentFile()
{
	
}
/********************************************************************************************/
bool DocumentFile::nextWord(Data& _data)
{
	size_t pos_ini=0, pos_end=0;
	
	if (_endBuffer)
	{
		if (eof)
			return false;
		else
			eof = readLine();
	}

	if (buffer.empty() && eof )
		return false;
		
		
	pos_end = buffer.find(" ");
	
	if ( (pos_end == string::npos) ) //es la ultima palabra en el buffer
	{
		_endBuffer = true;
		return nextWord(_data); //recursivo
	}	
	else
	{   _endBuffer = false;
		_data.word = buffer.substr( pos_ini, pos_end );
		buffer.erase( pos_ini, pos_end + 1);
	}
	
	_data.offset = offset++;

	return true;
}

/********************************************************************************************/
